//
//  SPHomeHeaderView.swift
//  Swift-demo
//
//  Created by zcp on 2021/10/9.
//

import UIKit


typealias moreBtnBlock = (_ param: Dictionary<String, Any>) -> Void

protocol homeHeaderViewDelegate: class {
    func homeHeaderViewMoreBtnAction(_ homeHeaderView: SPHomeHeaderView,param:[String: Any])
}


class SPHomeHeaderView: SPBaseCollectionReusableView {
    
    weak var delegate: homeHeaderViewDelegate?
    
    private var moreBtnBlock:  moreBtnBlock?
    
    lazy var imageV: UIImageView = {
        let imageV = UIImageView()
        return imageV
    }()
    
    lazy var titleL: UILabel = {
        let lable = UILabel()
        lable.font = UIFont.systemFont(ofSize: 18)
        lable.textColor = .black
        return lable
    }()
    
    private lazy var moreBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: "moreBtn"), for: .normal)
        btn.addTarget(self, action: #selector(moreBtnActionClick), for: .touchUpInside)
        return btn
    }()
    
    @objc func moreBtnActionClick() {
        guard let block = moreBtnBlock else {
            return
        }
        block(["ss":22])
        delegate?.homeHeaderViewMoreBtnAction(self, param: ["ss": 33])
    }
    
    func moreBtnAction(_ blcok: moreBtnBlock?)  {
        moreBtnBlock = blcok
    }
    
    override func initUI() {
        self.backgroundColor = .white
        self.addSubview(imageV)
        imageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(23)
        }
        
        self.addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.left.equalTo(imageV.snp_right).offset(5)
            make.centerY.equalTo(imageV)
        }
        
        self.addSubview(moreBtn)
        moreBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-10)
            make.centerY.equalTo(imageV)
            make.width.equalTo(30)
            make.height.equalTo(20)
        }
    }
}
